package com.central.apps.handler.project;

import com.central.app.common.base.BaseHandler;
import com.central.app.service.HandlerService;
import com.central.bizcommon.model.flow.FlowNode;
import com.central.bizcommon.model.flow.FlowOpinion;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 处理项目验收业务逻辑
 *
 * @author lidachao
 * @date 2022/9/28
 */
@Component
@Slf4j
public class ProjectAcceptanceHandler extends BaseHandler {

    @Autowired
    private HandlerService handlerService;

    @Override
    public String beforeExcuteFlow(String app, Long id, FlowNode flowNode, FlowOpinion op) throws Exception {
        if(flowNode.getId().equals("complete") && op.isFlag()) {
            // 查询进度申报信息
            List<Map<String, Object>> sfList = handlerService.findBySql("select proid, applytype, protype from gq_proacceptance where id = " + id);
            Map<String, Object> sfMap = sfList.get(0);
            Integer proid = (Integer) sfMap.get("proid");
            String applytype = (String) sfMap.get("applytype");
            String protype = (String) sfMap.get("protype");

            if ("内部验收".equals(applytype) && "最终验收".equals(protype)) {
                handlerService.updateBySql("update gq_proaccount set prostatus = '已验收' where id = " + proid);
            }
        }

        return null;
    }
}
